// 1.引入公用样式表
require("../../assets/css/index.less");

// 2.引入当前样式表
require("./login.less");

// 3.引入公用js模块
let dom = require("../../utils/dom.js");
let https = require("../../utils/https.js");
let local = require("../../utils/local.js");

// 页面加载事件
dom.ready(function () {
	dom.goTo("#register", "register");
	dom.goTo("#findPwd", "findPwd");
	dom.$("#btn").addEventListener("click", () => {
		// 获取用户输入的值
		let account = dom.$("#account").value;
		let password = dom.$("#pwd").value;

		if (account && password) {
			https.post("/api/user/login", { account, password }, function (res) {
				//判定
				if (res.errno === 0) {
					//登录成功
					alert("恭喜您!登录成功!");
					//存储
					local.set("t_k", res.data.token);
					//跳转到首页
					location.href = "home.html";
				} else {
					//登录失败
					alert("账号或密码有误!");
				}
			});
		}
	});
});
